home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 22 / AACD 22.iso / AACD / Online / Apache / include / php / Zend / zend_operators.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-21  |  9.3 KB  |  241 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Zend Engine                                                          |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998-2000 Zend Technologies Ltd. (http://www.zend.com) |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 0.92 of the Zend license,     |
  8.    | that is bundled with this package in the file LICENSE, and is        | 
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.zend.com/license/0_92.txt.                                |
  11.    | If you did not receive a copy of the Zend license and are unable to  |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@zend.com so we can mail you a copy immediately.              |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Zeev Suraski <zeev@zend.com>                                |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20.  
  21. #ifndef ZEND_OPERATORS_H
  22. #define ZEND_OPERATORS_H
  23.  
  24. #include <errno.h>
  25. #include <math.h>
  26.  
  27. #ifdef HAVE_IEEEFP_H
  28. #include <ieeefp.h>
  29. #endif
  30.  
  31.  
  32. #if 0&&WITH_BCMATH
  33. #include "ext/bcmath/libbcmath/src/bcmath.h"
  34. #endif
  35.  
  36. #define MAX_LENGTH_OF_LONG 18
  37. #define MAX_LENGTH_OF_DOUBLE 32
  38.  
  39. ZEND_API int add_function(zval *result, zval *op1, zval *op2);
  40. ZEND_API int sub_function(zval *result, zval *op1, zval *op2);
  41. ZEND_API int mul_function(zval *result, zval *op1, zval *op2);
  42. ZEND_API int div_function(zval *result, zval *op1, zval *op2);
  43. ZEND_API int mod_function(zval *result, zval *op1, zval *op2);
  44. ZEND_API int boolean_or_function(zval *result, zval *op1, zval *op2);
  45. ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2);
  46. ZEND_API int boolean_and_function(zval *result, zval *op1, zval *op2);
  47. ZEND_API int boolean_not_function(zval *result, zval *op1);
  48. ZEND_API int bitwise_not_function(zval *result, zval *op1);
  49. ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2);
  50. ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2);
  51. ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2);
  52. ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2);
  53. ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2);
  54. ZEND_API int concat_function(zval *result, zval *op1, zval *op2);
  55.  
  56. ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2);
  57. ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2);
  58. ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2);
  59. ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2);
  60. ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2);
  61. ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2);
  62. static inline int is_numeric_string(char *str, int length, long *lval, double *dval)
  63. {
  64.     long local_lval;
  65.     double local_dval;
  66.     char *end_ptr;
  67.  
  68.     if (!length) {
  69.         return 0;
  70.     }
  71.     
  72.     errno=0;
  73.     local_lval = strtol(str, &end_ptr, 10);
  74.     if (errno!=ERANGE && end_ptr == str+length) { /* integer string */
  75.         if (lval) {
  76.             *lval = local_lval;
  77.         }
  78.         return IS_LONG;
  79.     }
  80.  
  81.     errno=0;
  82.     local_dval = strtod(str, &end_ptr);
  83.     if (errno!=ERANGE && end_ptr == str+length) { /* floating point string */
  84.         if (! zend_finite(local_dval)) {
  85.             /* "inf","nan" and maybe other weird ones */
  86.             return 0;
  87.         }
  88.  
  89.         if (dval) {
  90.             *dval = local_dval;
  91.         }
  92. #if 0&&WITH_BCMATH
  93.         if (length>16) {
  94.             register char *ptr=str, *end=str+length;
  95.             
  96.             while(ptr<end) {
  97.                 switch(*ptr++) {
  98.                     case 'e':
  99.                     case 'E':
  100.                         /* scientific notation, not handled by the BC library */
  101.                         return IS_DOUBLE;
  102.                         break;
  103.                     default:
  104.                         break;
  105.                 }
  106.             }
  107.             return FLAG_IS_BC;
  108.         } else {
  109.             return IS_DOUBLE;
  110.         }
  111. #else
  112.         return IS_DOUBLE;
  113. #endif
  114.     }
  115.     
  116.     return 0;
  117. }
  118.  
  119. ZEND_API int increment_function(zval *op1);
  120. ZEND_API int decrement_function(zval *op2);
  121.  
  122. BEGIN_EXTERN_C()
  123. ZEND_API void convert_scalar_to_number(zval *op);
  124. ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC);
  125. ZEND_API void convert_to_long(zval *op);
  126. ZEND_API void convert_to_double(zval *op);
  127. ZEND_API void convert_to_long_base(zval *op, int base);
  128. ZEND_API void convert_to_null(zval *op);
  129. ZEND_API void convert_to_boolean(zval *op);
  130. ZEND_API void convert_to_array(zval *op);
  131. ZEND_API void convert_to_object(zval *op);
  132. ZEND_API void multi_convert_to_long_ex(int argc, ...);
  133. ZEND_API void multi_convert_to_double_ex(int argc, ...);
  134. ZEND_API void multi_convert_to_string_ex(int argc, ...);
  135. ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2);
  136. ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2);
  137. #define convert_to_string(op)            _convert_to_string((op) ZEND_FILE_LINE_CC)
  138.  
  139. ZEND_API double zend_string_to_double(const char *number, zend_uint length);
  140. END_EXTERN_C()
  141.  
  142. ZEND_API int zval_is_true(zval *op);
  143. ZEND_API int compare_function(zval *result, zval *op1, zval *op2);
  144. ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2);
  145. ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2);
  146.  
  147. ZEND_API void zend_str_tolower(char *str, unsigned int length);
  148. ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2);
  149. ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3);
  150. ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2);
  151. ZEND_API int zend_binary_zval_strncasecmp(zval *s1, zval *s2, zval *s3);
  152. ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2);
  153. ZEND_API int zend_binary_strncmp(char *s1, uint len1, char *s2, uint len2, uint length);
  154. ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2);
  155. ZEND_API int zend_binary_strncasecmp(char *s1, uint len1, char *s2, uint len2, uint length);
  156.  
  157. ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2);
  158. ZEND_API void zend_compare_symbol_tables(zval *result, HashTable *ht1, HashTable *ht2);
  159. ZEND_API void zend_compare_arrays(zval *result, zval *a1, zval *a2);
  160. ZEND_API void zend_compare_objects(zval *result, zval *o1, zval *o2);
  161.  
  162. ZEND_API int zend_atoi(const char *str, int str_len);
  163.  
  164. #define convert_to_ex_master(ppzv, lower_type, upper_type)    \
  165.     if ((*ppzv)->type!=IS_##upper_type) {                    \
  166.         if (!(*ppzv)->is_ref) {                                \
  167.             SEPARATE_ZVAL(ppzv);                            \
  168.         }                                                    \
  169.         convert_to_##lower_type(*ppzv);                        \
  170.     }
  171.  
  172. #define convert_to_writable_ex_master(ppzv, lower_type, upper_type)    \
  173.     if ((*ppzv)->type!=IS_##upper_type) {                            \
  174.         SEPARATE_ZVAL(ppzv);                                        \
  175.         convert_to_##lower_type(*ppzv);                                \
  176.     }
  177.  
  178.  
  179. #define convert_to_boolean_ex(ppzv)    convert_to_ex_master(ppzv, boolean, BOOL)
  180. #define convert_to_long_ex(ppzv)    convert_to_ex_master(ppzv, long, LONG)
  181. #define convert_to_double_ex(ppzv)    convert_to_ex_master(ppzv, double, DOUBLE)
  182. #define convert_to_string_ex(ppzv)    convert_to_ex_master(ppzv, string, STRING)
  183. #define convert_to_array_ex(ppzv)    convert_to_ex_master(ppzv, array, ARRAY)
  184. #define convert_to_object_ex(ppzv)    convert_to_ex_master(ppzv, object, OBJECT)
  185. #define convert_to_null_ex(ppzv)    convert_to_ex_master(ppzv, null, NULL)
  186.  
  187. #define convert_to_writable_boolean_ex(ppzv)    convert_to_writable_ex_master(ppzv, boolean, BOOL)
  188. #define convert_to_writable_long_ex(ppzv)        convert_to_writable_ex_master(ppzv, long, LONG)
  189. #define convert_to_writable_double_ex(ppzv)        convert_to_writable_ex_master(ppzv, double, DOUBLE)
  190. #define convert_to_writable_string_ex(ppzv)        convert_to_writable_ex_master(ppzv, string, STRING)
  191. #define convert_to_writable_array_ex(ppzv)        convert_to_writable_ex_master(ppzv, array, ARRAY)
  192. #define convert_to_writable_object_ex(ppzv)        convert_to_writable_ex_master(ppzv, object, OBJECT)
  193. #define convert_to_writable_null_ex(ppzv)        convert_to_writable_ex_master(ppzv, null, NULL)
  194.  
  195.  
  196. #define convert_scalar_to_number_ex(ppzv)                            \
  197.     if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) {        \
  198.         if (!(*ppzv)->is_ref) {                                        \
  199.             SEPARATE_ZVAL(ppzv);                                    \
  200.         }                                                            \
  201.         convert_scalar_to_number(*ppzv);                            \
  202.     }
  203.  
  204.  
  205.  
  206. #define Z_LVAL(zval)        (zval).value.lval
  207. #define Z_BVAL(zval)        ((zend_bool)(zval).value.lval)
  208. #define Z_DVAL(zval)        (zval).value.dval
  209. #define Z_STRVAL(zval)        (zval).value.str.val
  210. #define Z_STRLEN(zval)        (zval).value.str.len
  211. #define Z_ARRVAL(zval)        (zval).value.ht
  212. #define Z_OBJPROP(zval)        (zval).value.obj.properties
  213. #define Z_OBJCE(zval)        (zval).value.obj.ce
  214. #define Z_RESVAL(zval)        (zval).value.lval
  215.  
  216. #define Z_LVAL_P(zval_p)        Z_LVAL(*zval_p)
  217. #define Z_BVAL_P(zval_p)        Z_BVAL(*zval_p)
  218. #define Z_DVAL_P(zval_p)        Z_DVAL(*zval_p)
  219. #define Z_STRVAL_P(zval_p)        Z_STRVAL(*zval_p)
  220. #define Z_STRLEN_P(zval_p)        Z_STRLEN(*zval_p)
  221. #define Z_ARRVAL_P(zval_p)        Z_ARRVAL(*zval_p)
  222. #define Z_OBJPROP_P(zval_p)        Z_OBJPROP(*zval_p)
  223. #define Z_OBJCE_P(zval_p)        Z_OBJCE(*zval_p)
  224. #define Z_RESVAL_P(zval_p)        Z_RESVAL(*zval_p)
  225.  
  226. #define Z_LVAL_PP(zval_pp)        Z_LVAL(**zval_pp)
  227. #define Z_BVAL_PP(zval_pp)        Z_BVAL(**zval_pp)
  228. #define Z_DVAL_PP(zval_pp)        Z_DVAL(**zval_pp)
  229. #define Z_STRVAL_PP(zval_pp)    Z_STRVAL(**zval_pp)
  230. #define Z_STRLEN_PP(zval_pp)    Z_STRLEN(**zval_pp)
  231. #define Z_ARRVAL_PP(zval_pp)    Z_ARRVAL(**zval_pp)
  232. #define Z_OBJPROP_PP(zval_pp)    Z_OBJPROP(**zval_pp)
  233. #define Z_OBJCE_PP(zval_pp)        Z_OBJCE(**zval_pp)
  234. #define Z_RESVAL_PP(zval_pp)    Z_RESVAL(**zval_pp)
  235.  
  236. #define Z_TYPE(zval)        (zval).type
  237. #define Z_TYPE_P(zval_p)    Z_TYPE(*zval_p)
  238. #define Z_TYPE_PP(zval_pp)    Z_TYPE(**zval_pp)
  239.  
  240. #endif
  241.